import { createSlice } from '@reduxjs/toolkit';

const agentSlice = createSlice({
	name: 'agent',
	initialState: {
		id: '',
		org: '',
		role: '',
		fullName: '',
		clientId: '',
		avatar: '',
		userName: '',
		status: {
			logged: true, //登入
			ready: false, //就绪
			otherWork: false, //小休
			checkIn: false //签入
		}
	},
	reducers: {
		setAgentInfo(state, action) {
			return { ...state, ...action.payload };
		},

		setAgentStatus(state, action) {
			let status: any = {};
			switch (action.payload.key) {
				case 'ready':
					status = { ...state.status, ready: action.payload.value };
					break;
				case 'otherWork':
					status = { ...state.status, otherWork: action.payload.value };
					break;
				case 'checkIn':
					status = { ...state.status, checkIn: action.payload.value };
					break;
				default:
					status = state.status;
					break;
			}
			return { ...state, status: status };
		},
		logout() {
			return {
				id: '',
				org: '',
				role: '',
				fullName: '',
				clientId: '',
				avatar: '',
				userName: '',
				status: {
					logged: false, //登入
					ready: false, //就绪
					otherWork: false, //小休
					checkIn: false //签入
				}
			};
		},
		resetAmsStatus(state) {
			const status = {
				logged: false, //登入
				ready: false, //就绪
				otherWork: false, //小休
				checkIn: false //签入
			};
			return { ...state, status: status };
		}
	}
});

export const { setAgentInfo, setAgentStatus, logout, resetAmsStatus } = agentSlice.actions;
export default agentSlice.reducer;
